<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="fullName= {firstName:'ni',lastName:'xixi'}">change</button>
        <h3>全名：{{fullName}}</h3>
    </div>
    <script>
        const vm = new Vue({
            data() {
                return {
                    firstName: "wang",
                    lastName: "xiao xue"
                }
            },
            methods: {

            },
            //计算属性
            computed: {
                // fullName: {
                //     get() {
                //         console.log("getter");
                //         return (
                //             this.firstName.toLowerCase() + " " + this.lastName.toLowerCase()
                //         );
                //     },
                //     set(val) {
                //         /* set函数中的参数就是计算属性被设置的值 */
                //         console.log("setter", val);

                //         //setter中的逻辑我们可以自由发挥
                //         this.firstName = val.split(" ")[0];
                //         this.lastName = val.split(" ")[1];
                //     },
                // },
                // fullName(){
                //     return this.firstName.toLowerCase() + " " + this.lastName.toLowerCase()
                // }
                fullName:{
                    get(){
                        return this.firstName.toLowerCase() + " " + this.lastName.toLowerCase()
                    },
                    set(val){
                        this.firstName = val.firstName
                        this.lastName = val.lastName
                    }
                }
            }
        }).$mount("#app")
    </script>
</body>

</html>